package com.ruoyi.project.pm.pview.service;

import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.security.ShiroUtils;
import com.ruoyi.common.utils.text.Convert;
import com.ruoyi.project.pm.pview.domain.PmPview;
import com.ruoyi.project.pm.pview.mapper.PmPviewMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PmPviewServiceImpl implements PmPviewService {
    //声明mapper层属性
    @Autowired
    private PmPviewMapper pmPviewMapper;

    //删除项目类型
    @Override
    public int deleteTypeByIds(String proIds) {
        Integer[] troIds = Convert.toIntArray(proIds);

        return pmPviewMapper.deleteTypeByIds(troIds);
    }

    //保存修改项目类别
    @Override
    public int updateCmsType(PmPview pmPview) {
        pmPview.setProType(ShiroUtils.getLoginName());
        return pmPviewMapper.updateCmsTypeMapper(pmPview);
    }

    //获取要修改的公告信息
    @Override
    public PmPview selectTypeById(Integer proId) {
        return pmPviewMapper.selectTypeByIdMapper(proId);
    }


    //校验类型名称
    @Override
    public String checkTypeNameUnique(PmPview pmPview) {
        int proId = StringUtils.isNull(pmPview.getProId()) ? -1 : pmPview.getProId();
        PmPview info = pmPviewMapper.checkTypeNameUnique(pmPview.getProType());
        if (StringUtils.isNotNull(info) && info.getProId().intValue() != info.getProId().intValue())
        {
            return UserConstants.TYPE_NAME_NOT_UNIQUE;
        }
        return UserConstants.TYPE_NAME_UNIQUE;
    }

    //加载项目类型信息
    @Override
    public List<PmPview> selectCmsTypeList(PmPview pmPview) {

        return pmPviewMapper.selectCmsTypeListMapper(pmPview);

    }
}



